﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using System.Windows.Controls;

using FinalProject.UI;
using FinalProject.UI.Controls;
using System.Collections;

namespace FinalProject
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        private HLookup GetParentControlLookup(object sender)
        {
            HLookup result = null;
            if (sender is Button)
            {
                Button btnLookup = sender as Button;
                StackPanel pnStack = btnLookup.Parent as StackPanel;
                result = pnStack.TemplatedParent as HLookup;
            }
            else if (sender is TextBox)
            {
                TextBox txtLookUp = sender as TextBox;
                StackPanel pnStack = txtLookUp.Parent as StackPanel;
                result = pnStack.TemplatedParent as HLookup;
            }
            return result;
        }

        private void OpenSelectionForm(Type persistenceType)
        {
            LookupForm frmLookUp = new LookupForm(persistenceType);
            frmLookUp.FormSendSelected += frmLookUp_FormSendSelected;
            frmLookUp.ShowDialog();

        }

        private void frmLookUp_FormSendSelected(object sender)
        {

        }

        private void LookupButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            HLookup parentControl = this.GetParentControlLookup(sender);
            if (parentControl == null) return;
            this.OpenSelectionForm(parentControl.PersistenceType);
        }

        private void HLookupText_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
        {
            // TODO: Add event handler implementation here.
            TextBox lkuText = sender as TextBox;
            if (lkuText == null) return;

            
        }
    }
}
